import NodeUtil from "../Framework/Utils/NodeUtil";
import { ZTool } from "../Framework/Utils/ZTool";

const { ccclass, property } = cc._decorator;

@ccclass
export default class HPBar extends cc.Component {

    HPBarFG: cc.Sprite = null;

    Init(color: cc.Color = cc.Color.RED) {
        this.HPBarFG = NodeUtil.GetComponent("HPBarFG", this.node, cc.Sprite);

        this.HPBarFG.node.color = color;
        this.Set(1);
    }

    Set(rate: number) {
        rate = ZTool.Clamp(rate, 0, 1);
        this.HPBarFG.fillRange = rate;
    }
}
